<?php

require_once 'common.php';
require_once 'dataCenter.php';
require_once "MJDMReward.php";

log_action("In Page : ".__FILE__);

if(!isset($_SESSION)){session_start();}

$uid = GetSessionUID();

//the message return to html page
$response = "";

//get the parameter from post data
$method = $_POST["method"];
$id =isset($_POST["id"])?$_POST["id"]:"";
$taskname= isset($_POST["name"])?$_POST["name"]:"";
$points = isset($_POST["points"])?$_POST["points"]:"";
$url = isset($_POST["url"])?$_POST["url"]:"";

$reward = new Reward();

if($method == "add" or $method == "edit")
{
	if(strlen($taskname) <= 0 )
	{
		echo "Empty task name!" ;
		return;
	}
	if(strlen($points) <= 0)
	{
		echo "No points !";
		return ;
	}

	$reward->id = $id;
	$reward->name = $taskname;
	$reward->points = $points;
	$reward->uid = $uid;
	$reward->url = $url;

}

switch($method)
{
	case "add":
		AddReward($reward);
		$response = " A new reward was added!";
		break;
	case "edit":
		UpdateReward($reward);
		$response = "You've successfully changed the reward settings!";
		break;
	case "delete":
		DeleteReward($id);
		$response = "The reward was deleted!";
		break;
}


//return value
echo $response;

?>